home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
432_01
/
ptmid3
/
mod-form.txt
< prev
next >
Wrap
Text File
|
1994-04-17
|
20KB
|
392 lines
Noisetracker/Soundtracker/Protracker Module Format
--------------------------------------------------
Credits: Lars Hamre, Norman Lin, Kurt Kennett, Mark Cox, Peter Hanning,
Steinar Midtskogen, Marc Espie, and Thomas Meyer
(All numbers below are given in decimal)
4th Revision
Module Format:
# Bytes Description
------- -----------
20 The module's title, padded with null (\0) bytes. Original
Protracker wrote letters only in uppercase.
(Data repeated for each sample 1-15 or 1-31)
22 Sample's name, padded with null bytes. If a name begins with a
'#', it is assumed not to be an instrument name, and is
probably a message.
2 Sample length in words (1 word = 2 bytes). The first word of
the sample is overwritten by the tracker, so a length of 1
still means an empty sample. See below for sample format.
1 Lowest four bits represent a signed nibble (-8..7) which is
the finetune value for the sample. Each finetune step changes
the note 1/8th of a semitone. Implemented by switching to a
different table of period-values for each finetune value.
1 Volume of sample. Legal values are 0..64. Volume is the linear
difference between sound intensities. 64 is full volume, and
the change in decibels can be calculated with 20*log10(Vol/64)
2 Start of sample repeat offset in words. Once the sample has
been played all of the way through, it will loop if the repeat
length is greater than one. It repeats by jumping to this
position in the sample and playing for the repeat length, then
jumping back to this position, and playing for the repeat
length, etc.
2 Length of sample repeat in words. Only loop if greater than 1.
(End of this sample's data.. each sample uses the same format and they
are stored sequentially)
N.B. All 2 byte lengths are stored with the Hi-byte first, as is usual
on the Amiga (big-endian format).
1 Number of song positions (ie. number of patterns played
throughout the song). Legal values are 1..128.
1 Historically set to 127, but can be safely ignored.
Noisetracker uses this byte to indicate restart position -
this has been made redundant by the 'Position Jump' effect.
128 Pattern table: patterns to play in each song position (0..127)
Each byte has a legal value of 0..63 (note the Protracker
exception below). The highest value in this table is the
highest pattern stored, no patterns above this value are
stored.
(4) The four letters "M.K." These are the initials of
Unknown/D.O.C. who changed the format so it could handle 31
samples (sorry.. they were not inserted by Mahoney & Kaktus).
Startrekker puts "FLT4" or "FLT8" here to indicate the # of
channels. If there are more than 64 patterns, Protracker will
put "M!K!" here. You might also find: "4CHN", "6CHN" or "8CHN"
which indicates 4, 6 or 8 channels respectively. If no letters
are here, then this is the start of the pattern data, and only
15 samples were present.
(Data repeated for each pattern:)
1024 Pattern data for each pattern (starting at 0).
(Each pattern has same format and is stored in numerical order.
See below for pattern format)
(Data repeated for each sample:)
xxxxxx The maximum size of a sample is 65535 words. Each sample is
stored as a collection of bytes (length of a sample was given
previously in the module). Each byte is a signed value (-128
..127) which is the channel data. When a sample is played at a
pitch of C2 (see below for pitches), about 8287 bytes of
sample data are sent to the channel per second. Multiply the
rate by the twelfth root of 2 (=1.0595) for each semitone
increase in pitch eg. moving the pitch up 1 octave doubles the
rate. The data is stored in the order it is played (eg. first
byte is first byte played). The first word of the sample data
is used to hold repeat information, and will overwrite any
sample data that is there (but it is probably safer to set it
to 0).
The rate given above (8287) conveys an inaccurate picture of
the module-format - in reality it is different for different
Amigas. As the routines for playing were written to run off
certain interrupts, for different Amiga computers the rate to
send data to the channel will be different. For PAL machines
the clock rate is 7093789.2 Hz and for NTSC machines it is
7159090.5 Hz. When the clock rate is divided by twice the
period number for the pitch it will give the rate to send the
data to the channel, eg. for a PAL machine sending a note at
C2 (period 428), the rate is 7093789.2/856 ~= 8287.1369
(Each sample is stored sequentially)
Pattern Format:
Each pattern is divided into 64 divisions. By allocating different
tempos for each pattern and spacing the notes across different amounts
of divisions, different bar sizes can be accommodated.
Each division contains the data for each channel (1..4) stored after
each other. Channels 1 and 4 are on the left, and channels 2 and 3 are
on the right. In the case of more channels: channels 5 and 8 are on the
left, and channels 6 and 7 are on the right, etc. Each channel's data in
the division has an identical format which consists of 2 words (4
bytes). Divisions are numbered 0..63. Each division may be divided into
a number of ticks (see 'set speed' effect below).
Channel Data:
(the four bytes of channel data in a pattern division)
7654-3210 7654-3210 7654-3210 7654-3210
wwww xxxxxxxxxxxxxx yyyy zzzzzzzzzzzzzz
wwwwyyyy (8 bits) is the sample for this channel/division
xxxxxxxxxxxx (12 bits) is the sample's period (or effect parameter)
zzzzzzzzzzzz (12 bits) is the effect for this channel/division
If there is to be no new sample to be played at this division on this
channel, then the old sample on this channel will continue, or at least
be "remembered" for any effects. If the sample is 0, then the previous
sample on that channel is used. Only one sample may play on a channel at
a time, so playing a new sample will cancel an old one - even if there
has been no data supplied for the new sample. Though, if you are using a
"silence" sample (ie. no data, only used to turn off other samples) it
is polite to set its default volume to 0.
To determine what pitch the sample is to be played on, look up the
period in a table, such as the one below (for finetune 0). If the period
is 0, then the previous period on that channel is used. Unfortunately,
some modules do not use these exact values. It is best to do a binary-
search (unless you use the period as the offset of an array of notes..
expensive), especially if you plan to use periods outside the "standard"
range. Periods are the internal representation of the pitch, so effects
that alter pitch (eg. sliding) alter the period value (see "effects"
below).
C C# D D# E F F# G G# A A# B
Octave 1: 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453
Octave 2: 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226
Octave 3: 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113
Octave 0:1712,1616,1525,1440,1357,1281,1209,1141,1077,1017, 961, 907
Octave 4: 107, 101, 95, 90, 85, 80, 76, 71, 67, 64, 60, 57
Octaves 0 and 4 are NOT standard, so don't rely on every tracker being
able to play them, or even not crashing if being given them - it's just
nice that if you can code it, to allow them to be read.
Effects:
Effects are written as groups of 4 bits, eg. 1871 = 7 * 256 + 4 * 16 +
15 = [7][4][15]. The high nibble (4 bits) usually determines the effect,
but if it is [1